home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-01-05 | 7.1 KB | 344 lines | [TEXT/PJMM] |
- unit Tools;
-
- interface
-
- const
- HiliteMode = $938;
- GMDTrapNum = $AA2A;
-
- type
- QDGlobalsPtr = ^QDGlobalsRec;
- QDGlobalsRec = record
- randSeed: LongInt;
- screenBits: BitMap;
- arrow: Cursor;
- dkGray: Pattern;
- ltGray: Pattern;
- gray: Pattern;
- black: Pattern;
- white: Pattern;
- ThePort: GrafPtr;
- end;
-
- function QDGlobals: QDGlobalsPtr;
- function Strip2Size (theStr: Str255; theSize: Integer): Str255;
- function TrapAvailable (theTrap: Integer): Boolean;
- function BitPerPixel: Integer;
- procedure BlinkBtn (theDialog: DialogPtr; btnNum: Integer);
- function GetItemRect (theDialog: DialogPtr; theItem: Integer): Rect;
- procedure FrameItemRect (theDialog: DialogPtr; itemNo: Integer);
- procedure doBold (theDialog: DialogPtr; itemNo: Integer);
- function aStr2Num (NumStr: Str255): LongInt;
- function CenterHDialog (dlogID: Integer): Integer;
- procedure CenterToWindow (theWindow: WindowPtr);
- procedure SetCheck (theDialog: DialogPtr; checkNum: Integer; status: Boolean);
-
- implementation
-
- {----------------------------------------------}
-
- function QDGlobals: QDGlobalsPtr;
-
- const
- CurrentA5 = $904;
-
- var
- myPtr, myPtr2: ^LongInt;
-
- begin
- myPtr := Pointer(CurrentA5);
- myPtr2 := Pointer(myPtr^);
- QDGlobals := QDGlobalsPtr(myPtr2^ - 130 + 4);
- end;
-
- {---------------------------------------------------------}
-
- function Strip2Size (theStr: Str255; theSize: Integer): Str255;
-
- var
- ellipsisWid, newWid, newLen, wid: Integer;
-
- begin
-
- newWid := StringWidth(theStr);
- if (theSize > 0) and (length(theStr) > 0) then
- begin
- if newWid > theSize then
- begin
- ellipsisWid := CharWidth('…');
- wid := theSize;
- newLen := length(theStr);
- wid := wid - ellipsisWid;
-
- repeat
- newWid := newWid - CharWidth(theStr[newLen]);
- newLen := newLen - 1;
- until (newWid <= wid) or (length(theStr) = 0);
-
- newLen := newLen + 1;
- theStr[newLen] := '…';
- {$PUSH}
- {$R-}
- theStr[0] := chr(newLen);
- {$R+}
- end;
- end;
-
- Strip2Size := theStr;
-
- end; { Strip2Size }
-
- {---------------------------------------------------------------------}
-
- function BitPerPixel: Integer;
-
- begin
-
- if TrapAvailable(GMDTrapNum) then
- BitPerPixel := GetMainDevice^^.gdPMap^^.pixelSize
- else
- BitPerPixel := 1;
-
- end; { BitPerPixel }
-
- {--------------------------------------------------------}
-
- function NumToolboxTraps: Integer;
-
- const
- _InitGraf = $A86E;
-
- begin
-
- if NGetTrapAddress(_InitGraf, ToolTrap) = NGetTrapAddress($AA6E, ToolTrap) then
- NumToolboxTraps := $200
- else
- NumToolboxTraps := $400;
-
- end; { NumToolboxTraps }
-
- {--------------------------------------------------------}
-
- function GetTrapType (theTrap: Integer): TrapType;
-
- const
- trapMask = $0800;
-
- begin
-
- if BAND(theTrap, $07FF) > 0 then
- GetTrapType := ToolTrap
- else
- GetTrapType := OSTrap;
-
- end; { GetTrapType }
-
- {--------------------------------------------------------}
-
- function TrapAvailable (theTrap: Integer): Boolean;
-
- const
- _Unimplemented = $A89F;
-
- var
- tType: TrapType;
-
- begin
-
- tType := GetTrapType(theTrap);
- if tType = ToolTrap then
- begin
- theTrap := BAND(theTrap, $07FF);
- if theTrap >= NumToolboxTraps then
- theTrap := _Unimplemented;
- end;
- TrapAvailable := NGetTrapAddress(theTrap, tType) <> NGetTrapAddress(_Unimplemented, ToolTrap);
-
- end; { TrapAvailable }
-
- {------------------------------------------------}
-
- procedure BlinkBtn (theDialog: DialogPtr; btnNum: Integer);
-
- var
- item: Handle;
- box: Rect;
- kind: Integer;
- endTime: LongInt;
-
- begin
-
- GetDItem(theDialog, btnNum, kind, item, box);
- HiliteControl(ControlHandle(item), 1);
- Delay(10, endTime);
- HiliteControl(ControlHandle(item), 0);
-
- end; { BlinkBtn }
-
- {------------------------------------------------}
-
- function GetItemRect (theDialog: DialogPtr; theItem: Integer): Rect;
-
- var
- item: Handle;
- box: Rect;
- kind: Integer;
-
- begin
-
- GetDItem(theDialog, theItem, kind, item, box);
- GetItemRect := box;
-
- end; { GetItemRect }
-
- {---------------------------------------------------------------}
-
- procedure FrameItemRect (theDialog: DialogPtr; itemNo: Integer);
-
- { draw a rect around an item }
-
- var
- item: Handle;
- box: Rect;
- kind: Integer;
-
- begin
-
- GetDItem(theDialog, itemNo, kind, item, box);
- if kind = 16 then { dont known why I have to do this … }
- InsetRect(box, -3, -3);
- FrameRect(box);
-
- end; { FrameItemRect }
-
- {---------------------------------------------------------------}
-
- procedure doBold (theDialog: DialogPtr; itemNo: Integer);
-
- var
- item: Handle;
- box: Rect;
- kind: Integer;
- thePenState: PenState;
-
- begin
-
- GetPenState(thePenState);
- GetDItem(theDialog, itemNo, kind, item, box);
- InsetRect(box, -4, -4);
- PenSize(3, 3);
- if (ControlHandle(item)^^.contrlHilite = 0) then
- PenPat(QDGlobals^.black)
- else
- PenPat(QDGlobals^.gray);
- FrameRoundRect(box, 16, 16);
- SetPenState(thePenState);
-
- end; { DoBold }
-
- {--------------------------------------------------------}
-
- function aStr2Num (NumStr: Str255): LongInt;
-
- var
- aNum: LongInt;
-
- begin
-
- StringToNum(NumStr, aNum);
- aStr2Num := aNum
-
- end; { aStr2Num }
-
- {---------------------------------------------------------------------}
-
- function CenterHDialog (dlogID: Integer): Integer;
-
- type
- RectPtr = ^Rect;
- RectHandle = ^RectPtr;
-
- var
- theDlog: DialogPtr;
- temp: Integer;
- theHandle: Handle;
-
- begin
-
- temp := 0;
- theHandle := GetResource('DLOG', dlogID);
- if (theHandle <> nil) and (ResError = NoErr) then
- begin
- {• theDlog := GetNewDialog(dlogID, nil, Pointer(-1));•}
- {• with theDlog^.portRect do•}
- {• temp := right - left;•}
- with RectHandle(theHandle)^^ do
- temp := right - left;
- ReleaseResource(theHandle);
- with QDGlobals^.screenBits.bounds do
- temp := (right - left - temp) div 2;
- {DisposDialog(theDlog);}
- end;
- CenterHDialog := temp;
-
- end; { CenterHDialog }
-
- {---------------------------------------------------------------------}
-
- procedure CenterToWindow (theWindow: WindowPtr);
-
- type
- IntPtr = ^Integer;
-
- var
- where, org: Point;
- savePort: GrafPtr;
- prevWindow: WindowPtr;
- minV: Integer;
-
- begin
-
- GetPort(savePort);
- prevWindow := WindowPtr(WindowPeek(FrontWindow)^.nextWindow);
- prevWindow := FrontWindow;
- org := prevWindow^.portRect.topLeft;
- SetPort(prevWindow);
- LocalToGlobal(org);
- SetPort(theWindow);
- where.v := theWindow^.portRect.bottom - theWindow^.portRect.top;
- where.h := theWindow^.portRect.right - theWindow^.portRect.left;
- with prevWindow^.portRect do
- begin
- where.h := ((right - left) - where.h) div 2;
- where.v := ((bottom - top) - where.v) div 2;
- end;
- org.h := org.h + where.h;
- org.v := org.v + where.v;
- if org.h < 0 then
- org.h := 10;
- minv := 20 + IntPtr($BAA)^;
- if org.v < minv then
- org.v := minv;
-
- MoveWindow(theWindow, org.h, org.v, false);
- SetPort(savePort);
-
- end; { CenterToWindow }
-
- {------------------------------------------------}
-
- procedure SetCheck (theDialog: DialogPtr; checkNum: Integer; status: Boolean);
-
- var
- item: Handle;
- box: Rect;
- itemType: Integer;
-
- begin
-
- GetDItem(theDialog, checkNum, itemType, item, box);
- SetCtlValue(ControlHandle(item), Integer(status));
-
- end; { SetCheck}
-
- end.